<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>新增经验库</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lims/css/eleTree.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .layui-card-header{
            border-bottom: 1px solid #eee;
        }
        .newTable{
            width: 80%;
            margin: 0 auto;
        }
        .layui-form .one{
            /*margin-left: -60px;*/
            width: 100%;
            display: flex;
            flex-flow: row wrap;
            justify-content: space-around;
        }
        .layui-form-item{
            width: 33%;
        }
        .layui-inline{
            width: 40%;
            height: 38px;
        }
        .layui-form-label{
            width:100px;
            margin-left: -39px;
        }
        .layui-input-block{
            margin-left: 94px;
        }
        input::-webkit-input-placeholder {
            color: #aab2bd;
        }
        .buttonbottom{
            text-align: center;
        }
        .buttonbottom button{
            background-color: #009284;
            width: 90px;
            margin-top: 30px;
        }
        .layui-treeSelect .ztree li span.button.root_open:before, .layui-treeSelect .ztree li span.button.root_close:before{
            content: "\e623";
        }
        #memo{
            width:100%;
        }
        .inp{
            height: 33px;
            border:none
        }
        .select .layui-input{
            height: 28px;
        }
        .layui-table-cell .layui-select-title .layui-unselect{
            height: 28px;
        }
        .layui-table-cell {
            overflow: visible;
        }

        .layui-table-box {
            overflow: visible;
        }

        .layui-table-body {
            overflow: visible;
        }
        .taby{
            width:100%;
            min-height: 25px;
            line-height: 25px;
            text-align: center;
            border:1px solid #e6e6e6;
            border-collapse: collapse;
        }
        td{
            border:1px solid #e6e6e6;
            height: 40px;
            line-height: 40px;
        }
        th{
            border:1px solid #e6e6e6;
        }
        #add{
            width: 70px;
            position: absolute;
            /*right:180px;*/
            /*margin-top: 4px;*/
            /*visibility: hidden;*/
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="formTest" action=""style="width: 100%;margin: 0 auto;">
                <input type="hidden" name="equipId" id="layui-form">
                <div class="one" style="position: relative;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">设备名称:</label>
                        <div class="layui-input-block" >
                            <input type="text" name="equipName"  placeholder="请输入" autocomplete="off" class="layui-input typename">
                        </div>
                    </div>
                    <button type="button" class="layui-btn layui-btn-sm" lay-event="add" id="add">选择设备</button>

                    <div class="layui-form-item">
                        <label class="layui-form-label">固定资产编号:</label>
                        <div class="layui-input-block">
                            <input type="text" name="equipNo" placeholder="请输入" autocomplete="off" class="layui-input zichno">
                        </div>
                    </div>
                </div>

                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label labels">设备类型:</label>
                        <div class="layui-input-block">
                            <input type="text"  name="equipTypeName" lay-verify="required" placeholder="设备类型" autocomplete="off" class="layui-input eqtype">
                            <input type="hidden" name="equipStatuasId" id="equipStatuasId" disabled  placeholder="请输入" autocomplete="off" class="layui-input equipStatuasId">
                            <input type="hidden" name="equipTypeId" id="equipTypeId" disabled  placeholder="请输入" autocomplete="off" class="layui-input equipTypeId">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">出厂编号:</label>
                        <div class="layui-input-block">
                            <input type="text" name="factoryNo"lay-verify="required" placeholder="请输入设备名" autocomplete="off" class="layui-input chnum">
                        </div>
                    </div>
                </div>

                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label labels" style="">型号:</label>
                        <div class="layui-input-block">
                            <input type="text"  name="modelNo" lay-verify="required" placeholder="请输入设备编码" autocomplete="off" class="layui-input model">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">规格:</label>
                        <div class="layui-input-block">
                            <input type="text"name="spec"lay-verify="required" placeholder="请输入设备名" autocomplete="off" class="layui-input spec">
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label labels" style="">现象分类:</label>
                        <div class="layui-input-block faultType">
                            <select name="faultType" id="faultType" class="faultTypes">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <div class="layui-input-block" id="faultTypeInfo" style="display:none">
                            <input type="text" disabled name="faultType" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发生部位:</label>
                        <div class="layui-input-block">
                            <input type="text" name="faultPosition"lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input faultPosition">
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item" style="width:83%">
                        <label class="layui-form-label" >故障描述:</label>
                        <div class="layui-input-block">
                            <textarea name="faultDesc"  id="memo" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>

                <%--表格--%>
                <div>
                    <table class="taby"><%----%>
                        <thead>
                        <tr style="  background-color: #f2f2f2;">
                            <th style="width: 200px; height:40px; line-height:40px;" lay-data="{field:'username', width:200}"></th>
                            <th lay-data="{field:'experience', width:400}">内部故障诊断&维修措施</th>
                            <th lay-data="{field:'sign'}">外部故障诊断&维修措施</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>检测结果</td>
                            <td><input type="text" value="" name="inResult" class="layui-input inp inResult" autocomplete="off"></td>
                            <td><input type="text" value=""  name="outResult" class="layui-input inp outResult" autocomplete="off"></td>
                            <td><input type="hidden" value=""  name="experId" class="layui-input inp experId" autocomplete="off"></td>
                        </tr>
                        <tr>
                            <td>故障定位</td>
                            <td><input type="text" value=""  name="inFaultPosition" class="layui-input inp inFaultPosition" autocomplete="off"></td>
                            <td><input type="text" value=""  name="outFaultPosition" class="layui-input inp outFaultPosition" autocomplete="off"></td>

                        </tr>
                        <tr>
                            <td>原因分析</td>
                            <td><input type="text"value=""  name="inReason" class="layui-input inp inReason" autocomplete="off"></td>
                            <td><input type="text"value=""  name="outReason" class="layui-input inp outReason" autocomplete="off"></td>
                        </tr>
                        <tr>
                            <td>维修措施</td>
                            <td><input type="text" value="" name="inRepairMeasure" class="layui-input inp" id="inRepairMeasure"autocomplete="off"></td>
                            <td><input type="text" value="" name="outRepairMeasure" class="layui-input inp outRepairMeasure" autocomplete="off"></td>
                        </tr>
                        <tr>
                            <td>维修方式</td><%--下拉框--%>
                            <td>
                                <select name="inRepairMode"  id="inRepairMode" style="height: 28px">
                                    <option>请选择</option>
                                </select>
                            </td>
                            <td>
                                <select name="outRepairMode"  id="outRepairMode" style="height: 28px">
                                    <option>请选择</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>维修等级</td>
                            <td>
                                <select name="inRepairRank" class="inRepairRank" id="inRepairRank" style="height: 28px" autocomplete="off">
                                    <option>请选择</option>
                                </select>
                            </td>
                            <td>
                                <select name="outRepairRank" class="outRepairRank" id="outRepairRank" style="height: 28px" autocomplete="off">
                                    <option>请选择</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>维修预算</td>
                            <td><input type="text" value="" name="inPrice" class="layui-input inp inPrice" autocomplete="off"></td>
                            <td><input type="text" value="" name="outPrice" class="layui-input inp outPrice" autocomplete="off"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
    </div>

</div>
<script>
    // 获取地址栏参数值
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var equipId;
    var equipmentId
    var parentDta=parent.trObj;
    debugger
    var equipIds=parent.equipids;
    var btntype = getQueryString("btntype");    //详情
    var addbttn = getQueryString("addbttn");
    var btnedit = getQueryString('btnedit')
    layui.use(['table','form','layer'], function(){
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        console.log(equipIds,9876556789009876)
        //转换静态表格
        table.init('demo', {
            height: 315 //设置高度
            ,limit: 10 //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
        });

        //渲染新增时 现象分类 ajax
        $.ajax({
            url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_FAILURE'
            , type: 'post'
            , success: function (res) {
                var fault = ''
                for (var i = 0; i < res.data.length; i++) {
                    fault += '<option value="' + res.data[i].codeNo + '">' +  res.data[i].codeName + '</option>'
                }
                $('.faultTypes').append(fault)
                form.render('select');
            }
        })
        //添加经验
        $('#add').click(function () {
            layer.open({
                type: 2 //此处以iframe举例
                ,title: '选择设备'
                ,area: ['90%', '90%']
                ,maxmin: true
                ,content: '/experience/selectType'
                ,btn: ['确定', '取消']
                ,yes: function(index,layero){
                    layer.close(index);
                    equipId = $(layero).find("iframe")[0].contentWindow.equipId;    //父页面获取子页面的变量
                    equipids = $(layero).find("iframe")[0].contentWindow.equipids;
                    equipStatuasId = $(layero).find("iframe")[0].contentWindow.equipStatuasId
                    $.ajax({
                        url:'/equipment/getEquipInfoByequipId'
                        ,type:'post'
                        ,dataType: 'json'
                        ,data:{equipId:equipId,equipTypeId:equipids,equipStatuasCode:equipStatuasId}

                        ,success:function (res) {
                            eqdata = res.obj
                            equipmentId = eqdata.equipId    //选择设备的id
                            //回显添加经验的数据
                            $('.typename').val(eqdata.equipName)
                            $('.zichno').val(eqdata.equipNo)
                            $('.model').val(eqdata.modelNo)
                            $('.spec').val(eqdata.spec);
                            $('.chnum').val(eqdata.factoryNo)
                            $('.eqtype').val(eqdata.equipTypeName)
                            $('.equipStatuasId').val(eqdata.equipStatuasId)
                            $('.equipTypeId').val(eqdata.equipTypeId)

                        }
                    })
                    layer.closeAll();
                }
            });
        })

        /**
         * 详情页面
         */
        if(btntype =="details"){
            $("#add").hide();
            $("#faultTypeInfo").show()//隐藏现象分类input框
            $(".faultType").hide()

            $.ajax({
                url:'/experience/selectEquipmentByExperId?experId='+ parentDta.experId
                ,type:'post'
                ,dataType: 'json'
                ,success:function(res){
                    $('#inRepairMode').append("<option selected>"+undefind_nullStr(res.object.inRepairMode)+"</option>");
                    $('#outRepairMode').append("<option selected>"+undefind_nullStr(res.object.outRepairMode)+"</option>");
                    $('#inRepairRank').append("<option selected>"+undefind_nullStr(res.object.inRepairRank)+"</option>");
                    $('#outRepairRank').append("<option selected>"+undefind_nullStr(res.object.outRepairRank)+"</option>");
                     $('#inRepairMode').attr('disabled','disabled');    //方式的回显
                    $('#outRepairMode').attr('disabled','disabled');
                    $('#inRepairRank').attr('disabled','disabled');     //等级的回显
                    $('#outRepairRank').attr('disabled','disabled');
                    $('#memo').attr('readonly',true);
                    form.val("formTest", res.object);
                    $('.layui-form input[type=text]').attr("disabled", true)

                }
            })
        }else if(btnedit == "edit"){
            $("#faultTypeInfo").hide()//隐藏现象分类input框
            $(".faultType").show()
            // $('.ault').hide()
            $.ajax({
                url:'/experience/selectEquipmentByExperId?experId='+ parentDta.experId
                ,type:'post'
                ,dataType: 'json'
                ,success:function(res){
                    var $selectFalut=$("#faultType")//故障分类变量
                    var $select = $("#inRepairMode");   //定义的维修方式的变量
                    var $select1 = $("#inRepairRank");  //定义的维修等级的变量
                    var $selein = $("#outRepairMode")   //定义的是维修方式内部的变量
                    var $seleout = $("#outRepairRank")   //定义的是维修等级外部的变量
                    //渲染新增时 维修方式 ajax
                   var faultType = res.object.faultType
                    var inRepairRank = res.object.inRepairRank;
                    var outRepairRank = res.object.outRepairRank;
                    var inRepairMode = res.object.inRepairMode;
                    var outRepairMode = res.object.outRepairMode;
                    $.ajax({
                        url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_FAILURE'
                        , type: 'post'
                        , success: function (obj) {
                            var inMode = ''
                            for (var i = 0; i < obj.data.length; i++) {
                                var inModeName = obj.data[i].codeName
                                if(faultType==inModeName){
                                    inMode += '<option selected value="' + obj.data[i].codeNo + '">' +  undefind_nullStr(inModeName) + '</option>'
                                }else{
                                    inMode +='<option value="' + obj.data[i].codeNo + '">' +  undefind_nullStr(inModeName) + '</option>'
                                }
                            }
                            $('#faultType').append(inMode)
                            form.render('select');
                        }
                    })
                    $.ajax({
                        url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_REPAIR_MODE'
                        , type: 'post'
                        , success: function (obj) {
                            console.log(obj,'obj')

                            //
                            var inMode = ''
                            var outMode = ''
                            for (var i = 0; i < obj.data.length; i++) {
                                var inModeName = obj.data[i].codeName
                                var inModeId = obj.data[i].codeNo
                                if(inRepairMode==inModeName){
                                    inMode += '<option selected value="' + inModeId + '">' +  inModeName + '</option>'
                                }else{
                                    inMode +='<option value="' + inModeId + '">' +  inModeName + '</option>'
                                }
                                if(outRepairMode==inModeName){
                                    outMode += '<option selected value="' + inModeId + '">' +  inModeName + '</option>'
                                }else{
                                    outMode +='<option value="' + inModeId + '">' + inModeName + '</option>'
                                }
                            }
                            $('#inRepairMode').append(inMode)
                            $('#outRepairMode').append(outMode)
                            form.render('select');
                        }
                    })
                    //渲染新增时 维修等级 ajax
                    $.ajax({
                        url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_REPAIR_RANK'
                        , type: 'post'
                        , success: function (obj2) {
                            console.log(obj2,'obj2')
                            var inRank = ''
                            var outRank = ''

                            for (var i = 0; i < obj2.data.length; i++) {
                                var inRankName = obj2.data[i].codeName
                                var inRankId = obj2.data[i].codeNo
                                if(inRepairRank==inRankName){
                                    inRank += '<option selected value="' + inRankId + '">' +  inRankName + '</option>'
                                }else{
                                    inRank +='<option value="' + inRankId + '">' +  inRankName + '</option>'
                                }
                                if(outRepairRank==inRankName){
                                    outRank += '<option selected value="' + inRankId + '">' +  inRankName + '</option>'
                                }else{
                                    outRank +='<option value="' + inRankId + '">' +  inRankName + '</option>'
                                }

                            }
                            $('#inRepairRank').append(inRank)
                            $('#outRepairRank').append(outRank)
                            form.render('select');
                        }
                    })
                    form.val("formTest", res.object);
                }
            })
        }else if(addbttn =="getCheckData"){
                    //渲染新增时 维修方式 ajax
                    $.ajax({
                        url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_REPAIR_MODE'
                        , type: 'post'
                        , success: function (res) {
                            //
                            var fault = ''
                            for (var i = 0; i < res.data.length; i++) {
                                fault += '<option value="' + res.data[i].codeNo + '">' +  res.data[i].codeName + '</option>'
                            }

                            $('#inRepairMode').append(fault)
                            $('#outRepairMode').append(fault)
                            form.render('select');
                        }
                    })
                    //渲染新增时 维修等级 ajax
                    $.ajax({
                        url: '/equipment/selectAllCommonCode?parentTyepNo=EQUIP_REPAIR_RANK'
                        , type: 'post'
                        , success: function (res) {
                            var fault = ''
                            for (var i = 0; i < res.data.length; i++) {
                                fault += '<option value="' + res.data[i].codeNo + '">' +  res.data[i].codeName + '</option>'
                            }
                            $('#inRepairRank').append(fault)
                            $('#outRepairRank').append(fault)
                            form.render('select');
                        }
                    })

                }

    })
    //父级页面调用子级页面
    function addData() {
        var experience = {};
        var experId = $('.experId').val();
        if(experId==undefined||experId==''){
        }else{
            experience.experId =experId;
        }

        experience.equipName = $('.typename').val();
        experience.equipNo = $('.zichno').val();
        experience.equipTypeName = $('.eqtype').val();
        experience.factoryNo = $('.chnum').val();
        experience.modelNo = $('.model').val();
        experience.spec = $('.spec').val();
        experience.faultType = $('.faultTypes').val();
        experience.faultDesc = $("#memo").val();
        experience.faultPosition = $('.faultPosition').val();
        experience.inResult = $('.inResult').val();
        experience.outResult = $('.outResult').val();
        experience.inFaultPosition = $('.inFaultPosition').val();
        experience.outFaultPosition = $('.outFaultPosition').val();
        experience.inReason = $('.inReason').val();
        experience.outReason =  $('.outReason').val();
        experience.inRepairMeasure =  $('#inRepairMeasure').val();
        experience.outRepairMeasure = $('.outRepairMeasure').val();
        experience.inRepairMode =  $("#inRepairMode").val();
        experience.outRepairMode = $('#outRepairMode').val();
        experience.inRepairRank = $("#inRepairRank").val();
        experience.outRepairRank = $('#outRepairRank').val();
        experience.inPrice = $(".inPrice").val()
        experience.outPrice = $('.outPrice').val();
        experience.equipId=equipmentId;
        experience.equipStatuasCode=$("#equipStatuasId").val()
        experience.equipTypeId=$("#equipTypeId").val()
        return experience;
    }

    function undefind_nullStr(value) {
        if(value==undefined){
            return ""
        }
        return value
    }
</script>


</body>
</html>